package com.example.demos.service.Impl;

import com.example.demos.common.MyBatisUtils;
import com.example.demos.dao.UserTokenDao;
import com.example.demos.service.UserTokenService;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.SimpleFormatter;

@Service
public class UserTokenServiceImpl implements UserTokenService {



    @Override
    public int addAdminUserToken(Integer UserId, String Token, Integer state) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        UserTokenDao userTokenDao =  sqlSession.getMapper(UserTokenDao.class);
        Date date=new Date();//获取一个java.util包下的Date对象
        Timestamp time=new Timestamp(date.getTime());//然后将时间转换成数据库类型的datetime类型
        Map<String ,Object> map = new HashMap<String, Object>();
        map.put("UserId",UserId);
        map.put("Token",Token);
        map.put("state",state);
        map.put("createtime",time);
        System.out.println(map);

        int userToken =  userTokenDao.addUserToken(map);
        System.out.println(userToken);

        if (userToken>0){
            System.out.println("插入成功");
        }
        sqlSession.commit();
        sqlSession.close();

        return userToken;
    }

    @Override
    public boolean NewAdminUserToken(Integer UserId, String Token) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        UserTokenDao adminUserTokenDao =  sqlSession.getMapper(UserTokenDao.class);
        Boolean userToken = adminUserTokenDao.NewAdminUserToken(UserId,Token);
        sqlSession.close();
        return userToken;
    }
}
